<?php
//рус
include_once (_CORE_PATH . "lib_prototype.php");
define("MESSAGE_ERROR", 1);
define("MESSAGE_NOTICE", 2);
class messanger_class implements lib_prototype_class
{
    private $_messageOld;
    private $_messageNew;
    
    protected $_libs;
    
    public function __construct ()
    {
        $this->_libs = SysLoader::GetLibCollection();
        
        $this->_messageOld = (array) $this->_libs->session->GetValue('message');
        $this->_messageNew = array();
    }
    public function createMessage ($message, $message_type = MESSAGE_NOTICE)
    {
        if (! strlen($message)) return;
        $this->_messageNew[] = array('message' => $message , 'type' => $message_type);
    }
    public function getMessage ()
    {
        $messages = array_merge($this->_messageOld, $this->_messageNew);
        if (sizeof($messages))
            return array_shift($messages);
        else
            return false;
    }
    public function getAllMessages ()
    {
        $messages = array_merge($this->_messageOld, $this->_messageNew);
        $this->killMessages();
        return $messages;
    }
    public function killMessages ()
    {
        if (isset($this->_messageOld))
            $this->_messageOld = array();
        if (isset($this->_messageNew))
            $this->_messageNew = array();
    }
    public function __destruct ()
    {
        $this->_libs->session->SetValue('message', $this->_messageNew);
    }
}